package com.cheng.channel;


import com.cheng.channel.adapter.BaseStyleAdapter;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;


/**
 * 默认的频道适配样式，如果没有设置setAdapter，默认使用这个
 */
public abstract class DefaultStyleAdapter extends BaseStyleAdapter<DefaultStyleAdapter.DefaultViewHolder> {
    @Override
    public DefaultViewHolder createStyleView(Component parent, String channelName) {
        Text textView = new Text(parent.getContext());
        textView.setText(channelName);
        textView.setTextAlignment(TextAlignment.CENTER);
        textView.setTextSize(channelTextSize,Text.TextSizeType.PX);
        return new DefaultViewHolder(textView);
    }

    @Override
    public void setNormalStyle(DefaultViewHolder viewHolder) {
        viewHolder.textView.setTextColor(channelNormalTextColor);
        viewHolder.textView.setBackground(channelNormalBackground);
    }

    @Override
    public void setFixedStyle(DefaultViewHolder viewHolder) {
        viewHolder.textView.setTextColor(channelFixedTextColor);
        viewHolder.textView.setBackground(channelFixedBackground);
    }

    @Override
    public void setEditStyle(DefaultViewHolder viewHolder) {
        viewHolder.textView.setBackground(channelEditBackground);
        viewHolder.textView.setTextColor(channelNormalTextColor);
    }

    @Override
    public void setFocusedStyle(DefaultViewHolder viewHolder) {
        viewHolder.textView.setBackground(channelFocusedBackground);
        viewHolder.textView.setTextColor(channelFocusedTextColor);
    }

    void setBackgroundResource(Component view, Element background) {
        this.channelNormalBackground = background;
        view.setBackground(background);
    }

    void setTextColor(Component view, Color textColor) {
        this.channelFixedTextColor = textColor;
        Text textView = (Text) view;
        textView.setTextColor(textColor);
    }

    void setTextSize(Component view, int channelTextSize) {
        Text textView = (Text) view;
        textView.setTextSize(channelTextSize, Text.TextSizeType.PX);
    }

    private int channelTextSize;

    private Color channelNormalTextColor;

    private Element channelNormalBackground;

    private Color channelFixedTextColor;

    private Element channelFixedBackground;

    private Element channelEditBackground;

    private Element channelFocusedBackground;

    private Color channelFocusedTextColor;

    void setChannelTextSize(int channelTextSize) {
        this.channelTextSize = channelTextSize;
    }

    void setChannelNormalTextColor(Color channelNormalTextColor) {
        this.channelNormalTextColor = channelNormalTextColor;
    }

    void setChannelNormalBackground(Element channelNormalBackground) {
        this.channelNormalBackground = channelNormalBackground;
    }

    void setChannelFixedTextColor(Color channelFixedTextColor) {
        this.channelFixedTextColor = channelFixedTextColor;
    }

    void setChannelFixedBackground(Element channelFixedBackground) {
        this.channelFixedBackground = channelFixedBackground;
    }

    void setChannelEditBackground(Element channelEditBackground) {
        this.channelEditBackground = channelEditBackground;
    }

    void setChannelFocusedBackground(Element channelFocusedBackground) {
        this.channelFocusedBackground = channelFocusedBackground;
    }

    void setChannelFocusedTextColor(Color channelFocusedTextColor) {
        this.channelFocusedTextColor = channelFocusedTextColor;
    }

    public class DefaultViewHolder extends ViewHolder {
        private Text textView;

        public DefaultViewHolder(Component itemView) {
            super(itemView);
            textView = (Text) itemView;
        }
    }
}
